/**
 *
 * 全局路由
 *
 */

import { createRouter, createWebHashHistory } from 'vue-router'

/**
 *
 * 获取全部组件
 *
 */
let files = import.meta.glob('../views/*.vue')
const modules = {}
for (const key in files) {
  files[key]().then((res) => {
    modules[key.replace(/(\.\/module\/|\.js)/g, '')] = res.default
  })
}
console.warn(files)

const routes = [
  { path: '/', component: () => import('@renderer/views/TabsView.vue') },
  { path: '/home', component: () => import('@renderer/views/home.vue') },
  { path: '/Login', component: () => import('@renderer/views/Login.vue') }
]

const router = createRouter({
  // 4. Provide the history implementation to use. We are using the hash history for simplicity here.
  history: createWebHashHistory(),
  routes, // short for `routes: routes`
  // 是否应该禁止尾部斜杠。默认为假
  strict: true,
  scrollBehavior: () => ({ left: 0, top: 0 })
})

// reset router
export function resetRouter() {
  router.getRoutes().forEach((route) => {
    const { name } = route
    router.hasRoute(name) && router.removeRoute(name)
  })
}

export default router
